<template>
	<view class="contont">
		<view style="width: 100%;">
			<view class="" style="color: #4A4A4A;font-size: 14px;margin-top: 15px;margin-left: 15px;">
			<text style="color: #FE0700;width: 12px;height: 12px;">*</text>上传回单
		</view>
		<image v-for="(v,i) in imaged" :key="i" :src="v"  style="width: 355px;height: 160px;margin-left: 10px;margin-top: 10px;" mode="" v-if="imaged.length!=0" @click="imgs"></image>
		<image src="../../static/img/pic_shangchuan@2x.png" mode="" style="width: 355px;height: 160px;margin-left: 10px;margin-top: 10px;" @click="imgs" ></image>
		</view>
		<view style=" width:100%;color: #4A4A4A;font-size: 14px;font-weight: 500;margin:20px 0px 10px 22px;">备注</view>
		<view style="width: 100%;margin-top: 15px;">
				<textarea value="" placeholder="请输入回单备注（可不填）…" v-model="text"/>
		</view>
		<button @click="but">提交</button>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				imaged:[],
				text:"",
				add:"",
				list:""
			}
		},
		onLoad(option) {
			var that=this
					this.list=option.id
			// ajax({
			// 	url:"https://www.uhuoda.com/v1/appdriver/driverOrderInfo",
			// 	method:"post",
			// 	data:{
			// 		id:option.id,
			// 		type:option.type
			// 	},
			// 	success(res){
			// 	console.log(res)
			// 		that.list=res.data.message.oldorder.id
			// 	}
			// })
		},
		methods:{
			but(){
						
				uni.showLoading({
				    title: '加载中'
				});
				var _self=this
				var header;
						  header = { 
									
						    'content-type': 'multipart/form-data', 
									
							    'cookie':uni.getStorageSync("sessionid")//读取cookie
							
							  };
							   for (let i = 0; i < this.imaged.length; i++) {
				 uni.uploadFile({
				 url : 'https://www.uhuoda.com//v1/appdriver/order/addreports',
				 filePath: _self.imaged[i],
				 name: 'reportFile',
				 header:header,
				 formData: {
						orderid:_self.list,
						reportDetail:_self.text,	  			
				 },
			
				
				 success (uploadFileRes) {
				
				  if(JSON.parse(uploadFileRes.data).status=="OK"){
					  uni.hideLoading();
				  }else{
					  uni.hideLoading();
					  uni.showToast({
					      title: '提交失败请重新提交',
					  	icon:"none"
					  }) 
				  }
					
				  uni.switchTab({
				  	  url:"./Receipt"
				  })
				 }
				});
				
				 }
			},
			imgs(){
				var  _self = this;
					  wx.showActionSheet({
					      itemList: ['拍照','从手机相册选择'],
					    success(res) {
					      console.log(res.tapIndex)
					      if(res.tapIndex==0){ //0是拍照
					        wx.chooseImage({
					          count: 1,
					          sizeType: ['compressed'],
					          sourceType: ['camera'],
					          success: function (res) {
					             _self.imaged= res.tempFilePaths;
					           },
					        })
					      } else if(res.tapIndex==1){
					        wx.chooseImage({
					          count: 1,
					          sizeType: ['compressed'],
					          sourceType: ['album'],
					          success: function(res) {
					          _self.imaged= res.tempFilePaths;
					          },
					        })
					      }
					    }
					  })
			}
		}
	}
	
</script>

<style>
	textarea{
		width:355px;
		height:200px;
		border-radius:8px;
		border:1px solid rgba(240,240,240,1);
		margin-left: 10px;
		text-indent: 20px;
		padding-top: 12px;
	}
	button{
		width:355px;
		height:44px;
		background:rgba(4,42,88,1);
		border-radius:8px;
		margin-top: 50px;
		color: #FFFFFF;
	}
</style>
